package org.springsource.util;

import java.beans.PropertyEditorSupport;

import org.springsocial.domain.Team;
import org.springsocial.services.TeamService;

public class TeamEditor extends PropertyEditorSupport {
	 private final TeamService teamService;
	 public TeamEditor(TeamService teamService) {
	        this.teamService = teamService;
	    }
	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		Team team = teamService.getTeam(Long.parseLong(text));
		this.setValue(team);
	}
	
	@Override
	public String getAsText() {
		Team team = (Team) this.getValue();
		return Long.toString(team==null ? new Long(1) : team.getId());
	}
}
